<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      >
<head th:replace="fragments/tabhead::headc"></head>

<body>

<th:block layout:fragment="content">
<!-- 采购退货单 -->
<div style="margin-top:10px;">
  <form class="layui-form search" id="searchForm">
  <div class="layui-form-item layui-elem-quote">
     <div class="layui-inline">
      <label class="layui-form-label" style="width:90px">所属公司</label>
      <div class="layui-input-inline" style="width:165px">
        <select name="companyId"><option value="1">深圳企智达有限公司</option></select>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label" style="width:80px">客户</label>
      <div class="layui-input-inline" style="width:100px">
        <input type="tel" name="customerName" class="layui-input"/>
      </div>
    </div>
   <div class="layui-inline">
      <label class="layui-form-label" style="width:100px">审核状态</label>
      <div class="layui-input-inline" style="width:100px;">
        <select name="reviewStatus">
        	<option value="">全部</option>
        	<option th:each="s : ${status}" th:attr="value=${s.code}" th:text="${s.value}"></option>
        </select>
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label" style="width:60px">时间</label>
      <div class="layui-input-inline" style="width:100px">
        <input type="text" id="startDate" class="layui-input" name='startDate'/>
      </div>
       <div class="layui-form-mid">-</div>
      <div class="layui-input-inline" style="width:100px">
        <input type="text" id="endDate" class="layui-input" name="endDate"/>
      </div>
    </div>
    <div class="layui-inline">
      <div class="layui-input-inline" style="width:150px;">
        <button class="layui-btn" id="searchBtn" type="button" authcode="900093">查询</button>
        <button class="layui-btn" id="createBtn" type="button" authcode="900094">新增</button>
      </div>
    </div>
    
  </div>
 </form>
</div>

<table class="layui-table"  id="tab" lay-filter="tab"></table>
<script>
var ins,page,trobj,editdialogindex,data;
$(function(){ 
	
	layui.use(['table','layer'], function(){
		var table = layui.table;
		ins =table.render({ //其它参数在此省略
		 elem:"#tab",
		 url: '/stock/puoutbound/list?first=true',
		 cols:[[
			  {field:'id',width:100, sort: true,title:'出库单ID',fixed:'left'},
		      {field:'companyName', width:180,title:'所属公司'},
		      {field:'sourceOrderNo', width:120, sort: true,title:'来源单号'},
		      {field:'orderNo', width:180,title:'采购退货单编号'},
		      {width:160,field:'supplierName',title:'客户名称'},
		      {field:'supplierConnact', width:130, sort: true,title:'客户联系人'},
		      {field:'phone', width:120, sort: true,title:'联系电话'},
		      {field:'count', width:90,title:'出库总量'},
		      {field:'statementNamevar', width:90,title:'结算方式'},
		      {field:'statementDays', width:90,title:'结算天数'},
		      {field:'statementCurrency', width:90,title:'结算币种'},
		      {field:'statementExchangeRate', width:90,title:'结算汇率'},
		      {field:'statementTaxRate', width:90,title:'结算税率'},
		      
		      {field:'status', width:93, sort: true,title:'状态',templet: '#status'},
		      {field:'confirmPerson',width:100,title:'审核人'},
		      {field:'confirmDate', width:120, sort: true,title:'审核日期'},
		      {field:'modifyPerson', width:100, sort: true,title:'修改人'},
		      {field:'mofifyDate', width:120,title:'修改日期'},
		      {field:'createPerson', width:100, sort: true,title:'创建人'},
		      {field:'createDate', width:120, sort: true,title:'创建日期'},
		      {field:'remark', width:135, sort: true,title:'备注'},
		      {align:'center',width:330, toolbar:'#toolbar',title:'操作',fixed:'right'}
		 ]]
	    ,page: true //是否显示分页
	    ,limits: [10,20,50]
	    ,limit:10 //每页默认显示的数量
		  //where:{phone:phone}
		  //method: 'post'
		 ,done:function(res,curr,count){
			 console.log(res);
			 page = curr;
			    //得到当前页码
			    console.log(curr); 
			    
			    //得到数据总量
			    console.log(count);
		 }
		});
		
		table.on("tool(tab)",function(obj){
			data = obj.data; //获得当前行json数据
			var layEvent = obj.event; //获得 lay-event 对应的值
			trobj = obj;
			var tr = obj.tr; //获得当前行 tr 的DOM对象
			console.log(data.id);
			if(layEvent=='edit'){
				$.post('/stock/puoutbound/1/'+data.id, {}, function(str){
				editdialogindex = layer.open({
					id:"pwdupdateDialog",
									title:"修改采购退货单",
								    type: 1,
								    zIndex:10,
								    area: ['700px', '450px'],
								    content: str //注意，如果str是object，那么需要字符拼接。
								  });
								});
			}else if(layEvent=='view'){
				$.post('/stock/puoutbound/view/'+data.id, {}, function(str){
			          editdialogindex = layer.open({
			        	  id:"pwdupdateDialog",
			            title:"采购退货单",
			              type: 1,
			              zIndex:10,
			              area: ['700px', '400px'],
			              content: str //注意，如果str是object，那么需要字符拼接。
			            });
			          });
			}else if(layEvent=='detail'){
				window.location.href="/stock/outbounddetail/index?id="+data.id;
			}else if(layEvent=='del'){
				layer.confirm('真的删除行么', function(index){
			        layer.close(index);
				$.post('/stock/puoutbound/del', {"id":data.id}, function(str){
									if(str.code==200){
										layer.msg('删除成功！', {icon: 6});
										reloadData();
									}else{
										layer.msg('删除失败！', {icon: 5});
									}
									});
				});
			}else if(layEvent=="reviewed"||layEvent=="unreviewed"){
				if(layEvent=="unreviewed"){
					 layer.confirm('真的弃审行么', function(index){
					        layer.close(index);
					$.post('/stock/puoutbound/review', {"id":data.id,"status":"0"}, function(str){
						if(str.code==200){
							layer.msg('弃审成功！', {icon: 6});
							reloadData();							
						}else{
							layer.msg('弃审失败！'+data.message, {icon: 5});
						}
						});
					 });
				}else{
					layer.confirm('真的审核行么', function(index){
					        layer.close(index);
					$.post('/stock/puoutbound/review', {"id":data.id,"status":"1"}, function(str){
						if(str.code==200){
							layer.msg('审核成功！', {icon: 6});
							reloadData();
						}else{
							layer.msg('审核失败！'+data.message, {icon: 5});
						}
						});
				   });
				}
			}else if(layEvent=="close"){
			    layer.confirm('真的关闭行么', function(index){
			        layer.close(index);
			        //向服务端发送删除指令
			     
			        $.post('/stock/puoutbound/review', {"id":data.id,"status":"2"}, function(str){
						if(str.code==200){
							layer.msg('关闭成功！', {icon: 6});
							reloadData();
						}else{
							layer.msg('关闭失败！'+data.message, {icon: 5});
						}
						});
			    });
			}
		});
		function reloadData(){ 
			$(".layui-laypage-btn")[0].click();
		}
		
		$("#createBtn").click(function(){
			$.post('/stock/puoutbound/add/1', {}, function(str){
				editdialogindex = layer.open({
					id:"pwdupdateDialog",
									title:"新增采购退货单",
								    type: 1,
								    zIndex:10,
								    area: ['700px', '550px'],
								    content: str //注意，如果str是object，那么需要字符拼接。
								  });
								});
		});
		
		$("#searchBtn").click(function(){
			var phone = $("input[name='phone']").val();
			var table = layui.table;
		    ins.reload({url: '/stock/puoutbound/list',where:$("#searchForm").serializeJson()});
		});
	})
	
	layui.use("laydate",function(){
		var laydate = layui.laydate;
		laydate.render({
			  elem: '#startDate' //指定元素
			});
		laydate.render({
			  elem: '#endDate' //指定元素
			});
	});
	
	

}); 
</script>
<script type="text/html" id="status">
  {{#if (d.status==0){}}

  	未审核
  {{# }else if(d.status==1){}}
  	审核
  {{# }else if(d.status==2){}}
	关闭
  {{# }else if(d.status==3){}}
	完成
  {{# }}}
</script>
<script type="text/html" id="toolbar">
	<a class="layui-btn layui-btn-mini" lay-event="view" authcode="900095">查看</a>
  	<a class="layui-btn layui-btn-mini" lay-event="detail" authcode="900096">详情</a>
{{#if (d.status==0){}}
  	<a class="layui-btn layui-btn-mini" lay-event="edit" authcode="900098">修改</a>
  	<a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del" authcode="900099">删除</a>
  	<a class="layui-btn layui-btn-mini" lay-event="reviewed" authcode="900097">审核</a>
{{# }else if(d.status==1){}}
  	<a class="layui-btn layui-btn-mini" lay-event="unreviewed" authcode="900100">弃审</a>
{{# }}}
{{#if (d.status!=3){}}
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="close" authcode="900107">关闭</a>
{{# }}}
</script>
<!--<div th:replace="/department/model::modelDiv"></div>-->
</th:block>
</body>
</html>